insert
    overwrite
    table jms_dm.dm_dev_repair_network_monitor_network_summary_dt
    partition
    (dt)
select scan_network_code                  as scan_network_code --站点code
     , scan_network_name                  as scan_network_name --站点name
     , date_time                          as date_time         --日期
     , sum(if(before_type_code = '34' and before_network_type = 4 and before_dest_code = scan_network_code, 1,
              0))                         as cen_wxout_num     --中心维修出库数量
     , sum(if(scan_type_code = '07', 1, 0)) as net_wxin_num      --维修入库
     , sum(if(scan_type_code = '34', 1, 0)) as net_wxou_num      --维修出库数量
     , sum(if(next_type_code = '07' and next_network_type = 4 and scan_type_code = '34', 1,
              0))                         as cen_wxin_num      --中心维修入库数量
     , sum(if(scan_type_code = '11', 1, 0)) as net_bf_num        --报废数量维修
     , sum(if(scan_type_code = '50', 1, 0)) as net_wxp_num       --无芯片数量维修
     , sum(if(scan_type_code = '49', 1, 0)) as net_xpth_num      --芯片替换数量维修
     , sum(if(scan_type_code = '48', 1, 0)) as net_wxpd_num      --维修盘点数量维修
     , dt                                 as dt
from jms_dm.dm_dev_repair_network_monitor_rfid_detail_dt
where dt <= '{{ execution_date | cst_ds }}'
  and dt >= date_add('{{ execution_date | cst_ds }}', -2)
  and type = 1
group by scan_network_code
       , scan_network_name
       , date_time
       , dt
    distribute by dt
;
